﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.基础设置;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
<<<<<<<< HEAD:MedicalPCTerminal.Write.API/Appcation/CommandHandlers/BasicSettingsCommandHandler/AddDiseaseManagementCommandHandler.cs
using MedicalPCTerminal.Write.API.Appcation.Commands.BasicSettingsCommand;

namespace MedicalPCTerminal.Write.API.Appcation.CommandHandlers.BasicSettingsCommandHandler
========
using MedicalPCTerminal.Write.API.Appcation.Commands.基础设置;

namespace MedicalPCTerminal.Write.API.Appcation.CommandHandlers.基础设置
>>>>>>>> parent of fe317f5 (修改命名空间):MedicalPCTerminal.Write.API/Appcation/CommandHandlers/基础设置/AddDiseaseManagementCommandHandler.cs
{
    /// <summary>
    /// 种病管理添加命令处理
    /// 基础设置-
    /// </summary>
    public class AddDiseaseManagementCommandHandler : IRequestHandler<AddDiseaseManagementCommand, APIResult<int>>
    {
        /// <summary>
        /// SqlSugar
        /// </summary>
        private readonly SqlSugarContext sqlSugar;
        /// <summary>
        /// 映射
        /// </summary>
        private readonly IMapper mapper;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="sqlSugar">SqlSugar</param>
        /// <param name="mapper">映射</param>
        public AddDiseaseManagementCommandHandler(SqlSugarContext sqlSugar, IMapper mapper)
        {
            this.sqlSugar = sqlSugar;
            this.mapper = mapper;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<APIResult<int>> Handle(AddDiseaseManagementCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<int> result = new APIResult<int>();
                var model=mapper.Map<DiseaseManagement>(request);
                model.IsDel=false;
                var res = sqlSugar.db.Insertable(model).ExecuteCommand();
                if (res>0)
                {
                    result.Code = APIEnum.添加成功;
                    result.Msg = APIEnum.添加成功.ToString();
                    result.data = res;
                }
                else
                {
                    result.Code = APIEnum.添加失败;
                    result.Msg = APIEnum.添加失败.ToString();
                    result.data = res;
                }
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}
